//56.合并区间  https://leetcode.cn/problems/merge-intervals/description/?envType=problem-list-v2&envId=array

class Solution {
    public int[][] merge(int[][] intervals) {
      //处理空值情况
      if(intervals == null && intervals.length == 0){
        return new int[0][];
      }
      //将区间左端点进行排序
      Arrays.sort(intervals,(a,b) -> a[0] - b[0]);
      //创建链表
      List<int[]> inl = new ArrayList<>();
      inl.add(intervals[0]);
      //进行数组遍历
      for(int i = 0 ; i<intervals.length ;i++){
        int[] last = inl.get(inl.size()-1);
        int[] pcr = intervals[i];
        if(last[1] >= pcr[0]){
            last[1] = Math.max(last[1],pcr[1]);
        }else{
            inl.add(pcr);
        }
      }
      //返回数组
      return inl.toArray(new int[inl.size()][]);
    }
}